package com.ruoyi.peizhen.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.peizhen.domain.BusinessServer;
import com.ruoyi.peizhen.service.IBusinessServerService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 业务Controller
 * 
 * @author ruoyi
 * @date 2022-03-13
 */
@Controller
@RequestMapping("/peizhen/server")
public class BusinessServerController extends BaseController
{
    private String prefix = "peizhen/server";

    @Autowired
    private IBusinessServerService businessServerService;

    @RequiresPermissions("peizhen:server:view")
    @GetMapping()
    public String server()
    {
        return prefix + "/server";
    }

    /**
     * 查询业务列表
     */
    @RequiresPermissions("peizhen:server:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(BusinessServer businessServer)
    {
        startPage();
        List<BusinessServer> list = businessServerService.selectBusinessServerList(businessServer);
        return getDataTable(list);
    }

    /**
     * 导出业务列表
     */
    @RequiresPermissions("peizhen:server:export")
    @Log(title = "业务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(BusinessServer businessServer)
    {
        List<BusinessServer> list = businessServerService.selectBusinessServerList(businessServer);
        ExcelUtil<BusinessServer> util = new ExcelUtil<BusinessServer>(BusinessServer.class);
        return util.exportExcel(list, "业务数据");
    }

    /**
     * 新增业务
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存业务
     */
    @RequiresPermissions("peizhen:server:add")
    @Log(title = "业务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(BusinessServer businessServer)
    {
        return toAjax(businessServerService.insertBusinessServer(businessServer));
    }

    /**
     * 修改业务
     */
    @RequiresPermissions("peizhen:server:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        BusinessServer businessServer = businessServerService.selectBusinessServerById(id);
        mmap.put("businessServer", businessServer);
        return prefix + "/edit";
    }

    /**
     * 修改保存业务
     */
    @RequiresPermissions("peizhen:server:edit")
    @Log(title = "业务", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(BusinessServer businessServer)
    {
        return toAjax(businessServerService.updateBusinessServer(businessServer));
    }

    /**
     * 删除业务
     */
    @RequiresPermissions("peizhen:server:remove")
    @Log(title = "业务", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(businessServerService.deleteBusinessServerByIds(ids));
    }
}
